package mua.core.operation.judge;

import mua.core.operation.list.Run;
import mua.core.value.Expression;
import mua.core.value.FunctionBody;
import mua.core.value.List;
import mua.core.value.MuaValue;

import java.util.Scanner;

import static mua.core.interpreter.Util.judgeType;
import static mua.core.interpreter.Util.myTrim;

public class If {
    public static MuaValue run(MuaValue a, MuaValue b, MuaValue c, Scanner scanner, FunctionBody functionBody){
        String str;
        if(a.toString().equals("true")){
            str = myTrim(b.toString());
        }else{
            str = myTrim(c.toString());
        }
        //空表
        if(str.equals("[]")){
            return new List();
        }
        //单项
        else if(!str.contains(" ")){
            String temp = str.substring(1,str.length()-1);
            return judgeType(temp, functionBody);
        }else {
            return Run.run(new Expression(str), scanner, functionBody);
        }
    }

}
